package com.clear.club.circle.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.clear.club.circle.api.enums.IsDeletedFlagEnum;
import com.clear.club.circle.api.req.RemoveSensitiveWordsReq;
import com.clear.club.circle.api.req.SaveSensitiveWordsReq;
import com.clear.club.circle.server.dao.SensitiveWordsMapper;
import com.clear.club.circle.server.entity.po.SensitiveWords;
import com.clear.club.circle.server.service.SensitiveWordsService;
import org.springframework.stereotype.Service;

/**
 * 敏感词表(SensitiveWords)表服务实现类
 *
 * @author makejava
 * @since 2024-07-04 14:52:42
 */
@Service("sensitiveWordsService")
public class SensitiveWordsServiceImpl extends ServiceImpl<SensitiveWordsMapper, SensitiveWords> implements SensitiveWordsService {

    /**
     * 新增敏感词
     *
     * @param req
     */
    @Override
    public Boolean saveSensitiveWord(SaveSensitiveWordsReq req) {
        SensitiveWords sensitiveWord = new SensitiveWords();
        sensitiveWord.setWords(req.getWords());
        sensitiveWord.setType(req.getType());
        sensitiveWord.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        return this.save(sensitiveWord);
    }

    /**
     * 删除敏感词
     */
    @Override
    public Boolean removeSensitiveWord(RemoveSensitiveWordsReq req) {
        LambdaUpdateWrapper<SensitiveWords> update = Wrappers.<SensitiveWords>lambdaUpdate()
                .eq(SensitiveWords::getId, req.getId())
                .eq(SensitiveWords::getIsDeleted, IsDeletedFlagEnum.UN_DELETED.getCode())
                .set(SensitiveWords::getIsDeleted, IsDeletedFlagEnum.DELETED.getCode());
        return this.update(update);
    }
}
